<?php
session_start();
// TODO: dodawanie, edytowanie, usuwanie Review Request
class Controller_User_Reviewrequest extends Controller_User_Abstract
{	
	public function __construct(Controller_Front $frontController)
	{
		parent::__construct('user_reviewrequest', $frontController);
	}
	
	public function indexAction()
	{
		$this->view()->display('user_reviewrequest.tpl');
	}
	
	public function newAction()
	{
		$buttonName = 'Dodaj';
		$reviewrequest = new Reviewrequests();
		
		$this->view()->assign('reviewrequest', $reviewrequest);
		//$this->view()->assign('vortals', VortalsPeer::doSelect(new Criteria()));
		$this->view()->assign('editButton', $buttonName);
		$_SESSION['enable']=true;
		$this->view()->display('user_reviewrequest_edit.tpl');
	}
	
	public function checkAction()
	{		
		if (!empty($_POST['id_reviewrequest'])) {
			$id = $_POST['id_reviewrequest'];
			
			$reviewrequest = ReviewrequestsPeer::retrieveByPK($id);
		} else {
			$reviewrequest = new Reviewrequests();
		}
		
		if($_SESSION["enable"]==true) {
			$reviewrequest->setDescription($_POST['description']);
			$reviewrequest->setIdUser(Manager_User::getUser()->getIdUser());
			$reviewrequest->setIdRequestStatus('1');
			$reviewrequest->save();
			$this->ok('Review Request description was added and is awaiting for develop.');
			$_SESSION['enable']=false;			
		} else {
			$this->fail('Review Request description was not added and is awaiting for develop.');
		}
				

	}	
	
	
}